class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        lst = []
        length = 0
        for i in range(len(s)):
            if s[i] in lst:
                length = max(length, len(lst))
                index = lst.index(s[i])
                lst = lst[index+1:]
            lst.append(s[i])
        length = max(length, len(lst))
        return length


